package cn.schoolwow.util.domain.query.reflection;

import cn.schoolwow.util.module.query.reflection.domain.ReflectionOption;

public class QueryReflection {
    private ReflectionOption reflectionOption = new ReflectionOption();

    /**
     * 创建反射查询对象
     * */
    public static QueryReflection newQuery(Class clazz){
        QueryReflection queryReflection = new QueryReflection();
        queryReflection.reflectionOption.clazz = clazz;
        return queryReflection;
    }

    /**是否忽略不存在的字段*/
    public QueryReflection ignoreNotExistField(boolean ignoreNotExistField){
        reflectionOption.ignoreNotExistField = ignoreNotExistField;
        return this;
    }

    /**忽略常量字段*/
    public QueryReflection ignoreFinalField(boolean ignoreFinalField){
        reflectionOption.ignoreFinalField = ignoreFinalField;
        return this;
    }

    /**忽略常量字段*/
    public QueryReflection ignoreStaticField(boolean ignoreStaticField){
        reflectionOption.ignoreStaticField = ignoreStaticField;
        return this;
    }

    public QueryReflection addQuery(String fieldName){
        if(null==fieldName||fieldName.isEmpty()){
            return this;
        }
        reflectionOption.filterFieldNames.add(fieldName);
        return this;
    }

    public QueryReflection addQuery(String[] fieldNames){
        if(null==fieldNames||fieldNames.length==0){
            return this;
        }
        for(String fieldName:fieldNames){
            addQuery(fieldName);
        }
        return this;
    }

    public QueryReflection addQuery(FieldFilter fieldFilter){
        if(null==fieldFilter){
            return this;
        }
        reflectionOption.fieldFilter = fieldFilter;
        return this;
    }

    public QueryReflectionResponse execute(){
        return new QueryReflectionResponse(reflectionOption);
    }
}
